import { ICPU } from "../api/cpu";
import { IPPU } from "../api/ppu";

class DMA implements IDMA {
    cpu!: ICPU;
    ppu!: IPPU;


    copy(cpuBusAddr: number): void {
        // 64个精灵数据
        const data = new Uint8Array(256);

        for (let i = 0; i < 256; i++) {
            data[i] = (this.cpu as any).bus.readByte(cpuBusAddr + i);
        }

        this.ppu.dmaCopy(data);

        // DMA传输
        (this.cpu as any).suspendCycles = (this.cpu as any).cycles & 0x01 ? 513 : 514;
    }

}

export {
    DMA
}